﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;



namespace RuleCode
{
    public class zfunction
    {


        public static string CutString(string strOld, int lenght, string strReplaceMore)
        {
            int i = 0;
            int j = 0;
            foreach (char chr in strOld)
            {
                //判断字符中文还是英文
                if ((int)chr > 127)
                {
                    i += 2;
                }
                else
                {
                    i++;
                }
                if (i > lenght)
                {
                    strOld = strOld.Substring(0, j) + strReplaceMore;
                    break;
                }
                j++;
            }
            return strOld;

        }


        public static double str2double(string str)
        {
            try
            {
                return Convert.ToDouble(str);
            }
            catch (Exception)
            {

                return 0;
            }

        }

        static public Int32 str2int(string str)
        {
            try
            {
                return Convert.ToInt32(str);
            }
            catch (Exception)
            {

                return 0;
            }
            return 0;
        }


        public static decimal ConvertStrToDec(string number,int decimals)
        {
            decimal d = 0;
            try
            {
                d = Convert.ToDecimal(number);
            }
            catch { }
            d = Decimal.Round(d, decimals);
            return d;
        }
    }
}
